//
//  STDSShapenFillEffect.h
//  STDSRenderSDKIOS
//
//  Created by 陈学明 on 2023/3/27.
//

#ifndef STDSShapenFillEffect_h
#define STDSShapenFillEffect_h

#include "STDSBaseEffect.hpp"
#include <Basic/Attrib/STDSAttribFill.hpp>
#include <Basic/Path/STDSPath.hpp>
/// 形状填充效果
class STDSShapenFillEffect: public STDSBaseEffect {
public:
    STDSShapenFillEffect() {
        mEffectType = STDSEffectTypeFill;
    }
    ~STDSShapenFillEffect() {
//        printf("dealloc--STDSTintEffect\n");
    }
    void initGL() override {
        STDSBaseEffect::initGL();
//        mFillProgram = mContext->getProgram(kShaderSRCDarkAngle);
    }
    
    void setPath(shared_ptr<STDSPath> path) {
        mPath = path;
    }
    
public:
    void draw() override {
        mFillProgram->use();
        if (mTexture != nullptr) {
            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D, mTexture->getId());
            mFillProgram->setUniform(mFillProgram->getUniform("uTexture"), 0);
        }
        mAtbRect.setPosVex(mFillProgram->getAttrib("aPos"));
        mAtbRect.setPosTex(mFillProgram->getAttrib("aTexCoord"));
        mAtbRect.draw();
        mFillProgram->unuse();
    }

private:
    shared_ptr<STDSPath> mPath{nullptr};
    STDSAttribFill mFillAttrib;
    shared_ptr<STDSShaderProgram> mFillProgram{nullptr};
};
#endif /* STDSShapenFillEffect_h */
